package com.lcifn.spring.aop.bean;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * 浏览器通用上网代理
 * @author lichao
 *
 */
public class JdkBrowserProxy implements InvocationHandler{
	
	private Browser browser;
	
	public JdkBrowserProxy(Browser browser) {
		this.browser = browser;
	}
	
	public Object getProxy(){
		return Proxy.newProxyInstance(browser.getClass().getClassLoader(),
				browser.getClass().getInterfaces(), this);
	}

	public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
		encrypt();
		Object retVal = method.invoke(browser, args);
		decrypt();
		return retVal;
	}
	
	/**
	 * 加密
	 */
	private void encrypt(){
		System.out.println("encrypt ...");
	}
	
	/**
	 * 解密
	 */
	private void decrypt(){
		System.out.println("decrypt ...");
	}
}
